/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * <p>Project: javaseapp - Stream1
 * <p>Powered by webrx On 2021-08-12 09:14:04
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Stream1 {
    public static void main(String[] args) {
        try {
            FileOutputStream fos = new FileOutputStream("c:/user.txt");
            fos.write("Hello World 中文字符串\r\n".getBytes());
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        //此行代码的true 代表字节输出流为追加模式（没有文件建立文件并写入内容）
        //有文件，则指针调整到文件最后，并写入内容。
        //java 1.7 try with 会自动关闭流，
        try (FileOutputStream fos = new FileOutputStream("user.txt", true)) {
            fos.write("Hello World 中文字符串\r\n".getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        }

        //FileInputStream 读取内容
        try (FileInputStream fis = new FileInputStream("user.txt")) {
            String info = new String(fis.readAllBytes());
            System.out.println(info);
        } catch (IOException e3) {
            e3.printStackTrace();
        }
    }
}
